package logic

import (
	"context"
	"zhihu/zhihurpc/models/mysql"

	"zhihu/zhihurpc/internal/svc"
	"zhihu/zhihurpc/zhihurpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProblemAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewProblemAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProblemAddLogic {
	return &ProblemAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 问题
func (l *ProblemAddLogic) ProblemAdd(in *zhihurpc.ProblemAddRequest) (*zhihurpc.ProblemAddResponse, error) {
	// todo: add your logic here and delete this line
	problem := mysql.Problem{
		Content: in.Content,
		UserId:  in.UserId,
		Hot:     in.Hot,
	}
	mysql.DB.Debug().Create(&problem)
	return &zhihurpc.ProblemAddResponse{
		Id: int64(problem.ID),
	}, nil
}
